<?php
namespace App\Http\Controllers;

use App\Utility\MyRedis;
use Illuminate\Http\Request;

class LiveController extends BaseController
{
    /**
     * 直播测试
     */

    protected $livePrefix = 'vsh-live-';

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 设置
     */
    public function getOne(Request $request)
    {
        $uid = $request->post('uid', 0);
        if (!$uid) {
            return $this->toAppJson(-2);
        }
        //获取数据
        $rst = MyRedis::getOne($this->livePrefix.$uid);
        if (!$rst) {
            return $this->toAppJson(-100);
        }
        $dataArr = array(
            'uid' => $uid,
            'imgUrl' => $rst['imgUrl'],
            'imgWidth' => $rst['imgW'],
            'imgHeight' => $rst['imgH'],
        );
        return $this->toAppJson(0, $dataArr);
    }

    /**
     * 设置
     */
    public function setUpdate(Request $request)
    {
        $uid = $request->post('uid', 0);
        $imgUrl = $request->post('imgUrl', '');
        $imgWidth = $request->post('imgWidth', 0);
        $imgHeight = $request->post('imgHeight', 0);
        if (!$uid || !$imgUrl || !$imgWidth || !$imgHeight) {
            return $this->toAppJson(-2);
        }
        //更新数据
        $dataArr = array(
            'uid' => $uid,
            'imgUrl' => $imgUrl,
            'imgW' => $imgWidth,
            'imgH' => $imgHeight,
        );
        $rst = MyRedis::setOne($this->livePrefix.$uid, $dataArr);
        if (!$rst) {
            return $this->toAppJson(-100);
        }
        return $this->toAppJson(0);
    }
}